<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>

    <template id="my-app">
      您的问题：<input type="text" v-model="question" />
      <!-- <button @click='queryAnswer'>查找答案</button> -->
    </template>

    <script src="../js/Vue.js"></script>
    <script>
      const app = {
        template: '#my-app',
        data() {
          return {
            // 侦听question的变化时，去进行一些逻辑的处理（JS，网络请求）
            question: 'Hello World'
          }
        },
        watch: {
          /* 
					question侦听data中的属性的名称
						- newValue变化后的新值
						- oldValue变化前的旧值
				*/
          question(newValue, oldValue) {
            console.log(`新值：${newValue}，旧值：${oldValue}`)
            this.queryAnswer()
          }
        },
        methods: {
          queryAnswer() {
            console.log(`你的问题${this.question}的答案是哈哈哈哈`)
          }
        }
      }

      Vue.createApp(app).mount('#app')
    </script>
  </body>
</html>
